/**
 * <copyright>
 *
 * Copyright (c) 2011 Zeligsoft (2009) Limited
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors: 
 *   Zeligsoft (2009) Limited - Initial API and implementation
 *
 * </copyright>
 *
 */
package org.omg.deployment.components;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.BasicDiagnostic;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.WrappedException;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent;
import org.eclipse.emf.eef.runtime.context.PropertiesEditingContext;
import org.eclipse.emf.eef.runtime.impl.components.SinglePartPropertiesEditingComponent;
import org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.omg.deployment.DeploymentPackage;
import org.omg.deployment.InstanceDeploymentDescription;
import org.omg.deployment.InstanceResourceDeploymentDescription;
import org.omg.deployment.parts.DeployedResourcePropertiesEditionPart;
import org.omg.deployment.parts.DeploymentViewsRepository;


/**
 * @author Toby McClean; Zeligsoft (2009) Limited
 * @generated
 */
public class InstanceDeploymentDescriptionDeployedResourcePropertiesEditionComponent extends SinglePartPropertiesEditingComponent {

	/**
	 * @generated
	 */
	
	public static String DEPLOYEDRESOURCE_PART = "DeployedResource"; //$NON-NLS-1$

	
	/**
	 * Settings for deployedResources ReferencesTable
	 */
	protected ReferencesTableSettings deployedResourcesSettings;
	
	/**
	 * Settings for deployedSharedResources ReferencesTable
	 */
	protected ReferencesTableSettings deployedSharedResourcesSettings;
	
	
	/**
	 * Default constructor
	 * @generated
	 */
	public InstanceDeploymentDescriptionDeployedResourcePropertiesEditionComponent(PropertiesEditingContext editingContext, EObject instanceDeploymentDescription, String editing_mode) {
    super(editingContext, instanceDeploymentDescription, editing_mode);
    parts = new String[] { DEPLOYEDRESOURCE_PART };
    repositoryKey = DeploymentViewsRepository.class;
    partKey = DeploymentViewsRepository.DeployedResource.class;
  }

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#initPart(java.lang.Object, int, org.eclipse.emf.ecore.EObject, 
	 *      org.eclipse.emf.ecore.resource.ResourceSet)
	 * @generated
	 */
	public void initPart(Object key, int kind, EObject elt, ResourceSet allResource) {
    setInitializing(true);
    if (editingPart != null && key == partKey) {
      editingPart.setContext(elt, allResource);
      final InstanceDeploymentDescription instanceDeploymentDescription = (InstanceDeploymentDescription)elt;
      final DeployedResourcePropertiesEditionPart deployedResourcePart = (DeployedResourcePropertiesEditionPart)editingPart;
      // init values
      if (isAccessible(DeploymentViewsRepository.DeployedResource.DeployedResources.resources)) {
        deployedResourcesSettings = new ReferencesTableSettings(instanceDeploymentDescription, DeploymentPackage.eINSTANCE.getInstanceDeploymentDescription_DeployedResource());
        deployedResourcePart.initResources(deployedResourcesSettings);
      }
      if (isAccessible(DeploymentViewsRepository.DeployedResource.DeployedSharedResources.sharedResources)) {
        deployedSharedResourcesSettings = new ReferencesTableSettings(instanceDeploymentDescription, DeploymentPackage.eINSTANCE.getInstanceDeploymentDescription_DeployedSharedResource());
        deployedResourcePart.initSharedResources(deployedSharedResourcesSettings);
      }
      // init filters
      deployedResourcePart.addFilterToResources(new ViewerFilter() {
      
          /**
           * {@inheritDoc}
           * 
           * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
           */
          public boolean select(Viewer viewer, Object parentElement, Object element) {
            return (element instanceof String && element.equals("")) || (element instanceof InstanceResourceDeploymentDescription); //$NON-NLS-1$ 
          }
      
      });
      
      deployedResourcePart.addFilterToSharedResources(new ViewerFilter() {
      
          /**
           * {@inheritDoc}
           * 
           * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
           */
          public boolean select(Viewer viewer, Object parentElement, Object element) {
            return (element instanceof String && element.equals("")) || (element instanceof InstanceResourceDeploymentDescription); //$NON-NLS-1$ 
          }
      
      });
      
      // init values for referenced views
      
      // init filters for referenced views
      
    }
    setInitializing(false);
  }





	/**
	 * {@inheritDoc}
	 * @see org.eclipse.emf.eef.runtime.impl.components.StandardPropertiesEditionComponent#associatedFeature(java.lang.Object)
	 * @generated
	 */
	public EStructuralFeature associatedFeature(Object editorKey) {
    if (editorKey == DeploymentViewsRepository.DeployedResource.DeployedResources.resources) {
      return DeploymentPackage.eINSTANCE.getInstanceDeploymentDescription_DeployedResource();
    }
    if (editorKey == DeploymentViewsRepository.DeployedResource.DeployedSharedResources.sharedResources) {
      return DeploymentPackage.eINSTANCE.getInstanceDeploymentDescription_DeployedSharedResource();
    }
    return super.associatedFeature(editorKey);
  }

	/**
	 * {@inheritDoc}
	 * @see org.eclipse.emf.eef.runtime.impl.components.StandardPropertiesEditionComponent#updateSemanticModel(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
	 * @generated
	 */
	public void updateSemanticModel(final IPropertiesEditionEvent event) {
    InstanceDeploymentDescription instanceDeploymentDescription = (InstanceDeploymentDescription)semanticObject;
  }

	/**
	 * {@inheritDoc}
	 * @see org.eclipse.emf.eef.runtime.impl.components.StandardPropertiesEditionComponent#updatePart(org.eclipse.emf.common.notify.Notification)
	 * @generated
	 */
	public void updatePart(Notification msg) {
    if (editingPart.isVisible()) {	
      DeployedResourcePropertiesEditionPart deployedResourcePart = (DeployedResourcePropertiesEditionPart)editingPart;
      if (DeploymentPackage.eINSTANCE.getInstanceDeploymentDescription_DeployedResource().equals(msg.getFeature()) && isAccessible(DeploymentViewsRepository.DeployedResource.DeployedResources.resources))
        deployedResourcePart.updateResources();
      if (DeploymentPackage.eINSTANCE.getInstanceDeploymentDescription_DeployedSharedResource().equals(msg.getFeature()) && isAccessible(DeploymentViewsRepository.DeployedResource.DeployedSharedResources.sharedResources))
        deployedResourcePart.updateSharedResources();
      
    }
  }


	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#validateValue(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
	 * @generated
	 */
	public Diagnostic validateValue(IPropertiesEditionEvent event) {
    Diagnostic ret = Diagnostic.OK_INSTANCE;
    if (event.getNewValue() != null) {
      try {
      } catch (IllegalArgumentException iae) {
        ret = BasicDiagnostic.toDiagnostic(iae);
      } catch (WrappedException we) {
        ret = BasicDiagnostic.toDiagnostic(we);
      }
    }
    return ret;
  }

}
